/**
 * 
 */
package com.liuqing.www.文件下载;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageFilter;
import java.awt.image.ImageProducer;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.game.common.SessionManager;
import com.game.common.UserContext;
import com.game.map.service.MapBLH;
import com.game.map.vo.MapInfo;
import com.game.skill.SkillBattle;
import com.game.user.OnlineUserInfo;

/**
 * @author KevinBian
 * 
 */
public class BarHPServlet extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
//	private static int width = 100 ;					//图片宽度
//	private static int height = 10 ;					//图片高度

	public BarHPServlet() {
		super();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("image/jpeg");
		String sessionid = request.getParameter("sessionid");
		OnlineUserInfo user = UserContext.get(sessionid);
		
		long hp = user.getHpSUM();
		long hpup = user.getHpupSUM();
		long bai = (hp * 100) / (hpup ) ;			//当前气血所占气血上限百分比
		
		int width = 100 ;							//图片宽度
		int height = 10 ;							//图片高度
		
		long cuhp = width - bai ;
		
		BufferedImage img = new BufferedImage(width, height,
				BufferedImage.TYPE_INT_RGB);
		
		Graphics2D g = img.createGraphics();
		g.setColor(Color.red);
		g.fillRect(0, 0, width, height);
		g.setColor(Color.lightGray);
		g.fillRect(width - (int)cuhp, 0, width, height);
		g.setColor(Color.black);
		String str = hp + "/" + hpup;
		Font font = new Font("", Font.BOLD, 12);
		g.setFont(font);
		g.drawString(str, (width / 2) - (str.length() * 3),height);
		
		
		g.drawImage(img, 0, 0, null);
		g.dispose();
		img.flush();

		ImageIO.write(img, "png", response.getOutputStream());
	}
}
